﻿var pagecount = "0";
var num = 0;
var page = 1;
var keyword = ""; //关键词
var hannelid = ""; //频道id
var hid = "";
var itemCount = 0;

$(document).ready(function () {
    if ("wap" == getUrlArgStr("sources")) {
        $(".wamtop").css("display", "none");
    }
    load(page);
    $(window).bind("scroll", function () {
        //当滚动条滚动时
        var scollTop = $(this).scrollTop() + $(this).height();
        var scollH = $(document).height();

        if (scollH - scollTop < 100) {
            // Alert("100");
            if (wait.isShow) { return; } //如果正在加载，则返回  
            page++;
            load(page);

        }
        return false;
    });
});

function load(page) {
    if (pagecount == "1") { return; }
    if (!islogin()) { window.location.href = 'login.html'; return; }
    ajax.getarticleList("channel_id=" + hannelid + "&author_id=" + userid + "&key_word=" + keyword + "&page_index=" + page, function (data) {
        if (data.code == "4") { Alert(data.msg.toString()); pagecount = "1"; return; }
        if (data.item.pageCount < page) {
            if (pagecount == "0")
                Alert('到底了！');
            pagecount = "1"; return;
        }
        itemCount = data.item.itemCount;
        $(".topcententxt").html("我的原创 (" + data.item.itemCount + ")");
        $(data.item.table).each(function () {
            num++;
            //默认图片
            var logoimg = this.logo == null ? "img/30.png" : this.logo;
            var titles = this.title;
            if (titles.length > 12)
                titles = titles.substr(0, 12) + "...";
            $(".tg_select").append("<div class=\"centenlist\"><div class=\" centenimg\"><img src=\"" + logoimg + "\"  /></div><div class=\"cententxt\"  onclick=\"window.location.href='to_detail.aspx?article_id=" + this.id + "'\"><div class=\"cententxttop\"><strong>" + titles + "</strong></div><div class=\"centenTime\"><div class=\"centenpostion\">" + this.date.substr(0, 10) + "<div class=\"centenflow\">  <img src=\"img/flow.jpg\"> " + this.click + "</div></div><div class=\"check\"><img src=\"img/Delete2.jpg\" class=\"checkimg\"  /><input type=\"hidden\" name=\"checkid\" value=\"" + this.id + "\" /></div></div></div></div>");
        });
        loadhtml();

    });
}

function loadhtml() {
    $(".check").click(function () {
        if (confirm($(this).parent().parent().parent().find('strong').html() + "\n\n  确定删除？")) {

            DeleteCollection($(this).children(":last").val(), $(this));
        }
        return false;
    });

}

function DeleteCollection(id, obj) {

    ajax.Detelearticle("id=" + id, function (data) {

        if (data.msg.toString() == "成功") {
            obj.parent().parent().parent().hide(500);
          
            $(".topcententxt").html("我的原创 (" +   --itemCount +")");

        }
        else {
            Alert(data.msg.toString());
        }
    });

}


